import { UserAuth, GetCasterDepartment, GetCasterPlace } from '../../utils/hooks';
import NotAuth from '../../components/NotAuth';
import { useState, useEffect, useRef } from 'react';
import {
  Layout,
  Cascader,
  Row,
  Col,
  Select,
  Input,
  Radio,
  Form,
  Spin,
  Button,
  message,
} from 'antd';
import axios from 'axios';
import Config from '../../Config';
import './index.css';
import { Map as BMap, Marker } from 'react-bmapgl';
const { Header, Content } = Layout;
const { Option } = Select;
const DeConfig = () => {
  const [deButtonLoading, setDeButtonLoading] = useState(false);
  const [placeButtonLoading, setPlaceButtonLoading] = useState(false);
  const [refresh, SetRefresh] = useState(true);
  const [refresh1, SetRefresh1] = useState(true);
  let value = {
    label: '无（需创建根部门请选选项，添加子部门）',
    value: -1,
  };
  let value1 = {
    label: '无（需创建根存放地请选此选项，添加子存放地）',
    value: -1,
  };
  const { departmentList, departmentOriginList } = GetCasterDepartment(value, refresh);
  const { placeList, placeOriginList } = GetCasterPlace(value1, refresh1);
  const [selectOpion, SetselectOpion] = useState(0);
  const [placeOption, SetPlaceOption] = useState(0);
  const [placeSelectList, SetPlaceSelectList] = useState([]);
  const [mapCenter, SetMapCenter] = useState({ lng: 116.402544, lat: 39.928216 });
  const [mapZoom, SetMapZoom] = useState(11);
  const [mapTilt, SetMapTilt] = useState(45);
  const [departmentForm] = Form.useForm();
  const [placeForm] = Form.useForm();

  const [degreeForm] = Form.useForm();
  const [degreeLoading, SetDegreeLoading] = useState(true);
  const [degreeButtonLoading, SetDegreeButton] = useState(false);
  const [defaultDegree, SetdefaultDegree] = useState({
    register: 0,
    edit: 0,
    delete: 0,
  });
  const [degreeRefresh, SetdegreeRefresh] = useState(true);

  const [isAvaliable, SetisAvaliable] = useState(false);
  const [MarkerCount, SetMarkerCount] = useState(0);
  const mapref = useRef();
  const [Marker1, SetMarker1] = useState({
    show: false,
    lng: 116.402544,
    lat: 39.928216,
  });
  const [Marker2, SetMarker2] = useState({
    show: false,
    lng: 116.402544,
    lat: 39.928216,
  });
  useEffect(() => {
    SetDegreeLoading(true);
    axios
      .get(Config.baseURL + '/instrument/examineDegree')
      .then(res => {
        if (res.data.code == 1) {
          SetdefaultDegree(res.data.data);
          degreeForm.setFieldsValue(res.data.data);
          SetDegreeLoading(false);
        } else if (res.data.code >= 10000) {
          message.error(res.data.message, 2);
        }
      })
      .catch(err => {
        message.error('服务器出错，请联系管理员', 2);
        console.log(err);
      });
  }, [degreeRefresh]);
  const degreeSubmit = () => {
    SetDegreeButton(true);
    let data = degreeForm.getFieldValue();
    console.log(data);
    axios
      .post(Config.baseURL + '/instrument/changeDegree', data)
      .then(res => {
        if (res.data.code == 1) {
          SetdegreeRefresh(!degreeRefresh);
          message.success('修改成功', 2);
          SetDegreeButton(false);
        } else if (res.data.code >= 10000) {
          message.error(res.data.message, 2);
          SetDegreeButton(false);
        }
      })
      .catch(err => {
        message.error('服务器出错，请联系管理员', 2);
        SetDegreeButton(false);
      });
  };
  useEffect(() => {
    let placeMap = new Map();
    for (let i = 0; i < placeOriginList.length; i++) placeMap.set(placeOriginList[i].placeId, i);
    ClearMark();

    if (placeOption == 1 || placeOption == 4) {
      SetisAvaliable(false);
      if (placeSelectList.length >= 1) {
        if (placeSelectList[0] == -1) {
          SetMapZoom(12);
          SetMapCenter({
            lng: 116.402544,
            lat: 39.928216,
          });
          SetMarker1({
            show: false,
          });
          SetMarker2({
            show: false,
          });
        } else {
          let first_Node = placeOriginList[placeMap.get(placeSelectList[0])];
          SetMarker1({
            show: true,
            lng: first_Node.lng,
            lat: first_Node.lat,
          });
          if (placeSelectList.length == 1) {
            SetMapZoom(18.464731475545832);
            SetMapCenter({
              lng: first_Node.lng,
              lat: first_Node.lat,
            });
          }
        }
      }
      if (placeSelectList.length == 2) {
        let second_Node = placeOriginList[placeMap.get(placeSelectList[1])];
        SetMarker2({
          show: true,
          lng: second_Node.lng,
          lat: second_Node.lat,
        });
        SetMapZoom(19.807794246889994);
        SetMapCenter({
          lng: second_Node.lng,
          lat: second_Node.lat,
        });
      }
    }

    if (placeOption == 2) {
      if (placeSelectList.length == 2) {
        message.warn('无法添加为改存放地添加子存放地', 2);
        SetisAvaliable(false);
      } else if (placeSelectList.length == 1) {
        if (placeSelectList[0] == -1) {
          SetMapZoom(12);
          SetMapCenter({
            lng: 116.402544,
            lat: 39.928216,
          });
          SetisAvaliable(true);
          SetMarkerCount(1);
        } else if (placeSelectList[0] >= 0) {
          let first_Node = placeOriginList[placeMap.get(placeSelectList[0])];
          SetMarker1({
            show: true,
            lng: first_Node.lng,
            lat: first_Node.lat,
          });
          SetisAvaliable(true);
          SetMarkerCount(2);
        }
      }
    }

    if (placeOption == 3) {
      if (placeSelectList[0] == -1) {
        message.warn('无法改变改存放地坐标', 2);
        SetisAvaliable(false);
      } else {
        SetisAvaliable(true);
        SetMarkerCount(placeSelectList.length);
        if (placeSelectList.length >= 1) {
          let first_Node = placeOriginList[placeMap.get(placeSelectList[0])];
          SetMarker1({
            show: true,
            lng: first_Node.lng,
            lat: first_Node.lat,
          });
          if (placeSelectList.length == 1) {
            SetMapZoom(18.464731475545832);
            SetMapCenter({
              lng: first_Node.lng,
              lat: first_Node.lat,
            });
          }
        }
        if (placeSelectList.length == 2) {
          let second_Node = placeOriginList[placeMap.get(placeSelectList[1])];
          SetMarker2({
            show: true,
            lng: second_Node.lng,
            lat: second_Node.lat,
          });
          SetMapZoom(19.807794246889994);
          SetMapCenter({
            lng: second_Node.lng,
            lat: second_Node.lat,
          });
        }
      }
    }

    if (placeSelectList.length >= 1) {
      if (placeSelectList[0] == -1) {
        SetMapZoom(12);
        SetMapCenter({
          lng: 116.402544,
          lat: 39.928216,
        });
        SetMarker1({
          show: false,
        });
        SetMarker2({
          show: false,
        });
      } else {
        let first_Node = placeOriginList[placeMap.get(placeSelectList[0])];
        SetMarker1({
          show: true,
          lng: first_Node.lng,
          lat: first_Node.lat,
        });
        if (placeSelectList.length == 1) {
          SetMapZoom(18.464731475545832);
          SetMapCenter({
            lng: first_Node.lng,
            lat: first_Node.lat,
          });
        }
      }
    }
    if (placeSelectList.length == 2) {
      let second_Node = placeOriginList[placeMap.get(placeSelectList[1])];
      SetMarker2({
        show: true,
        lng: second_Node.lng,
        lat: second_Node.lat,
      });
      SetMapZoom(19.807794246889994);
      SetMapCenter({
        lng: second_Node.lng,
        lat: second_Node.lat,
      });
    }
  }, [placeOption, placeSelectList]);
  const ClearMark = () => {
    SetMarker1({
      show: false,
    });
    SetMarker2({
      show: false,
    });
  };
  const SelectRender = () => {
    if (selectOpion == 2) {
      return (
        <Col span={6}>
          <Form.Item
            name="newName"
            label={'请输入子部门名'}
            style={{ marginLeft: '20px', marginTop: '15px' }}
          >
            <Input style={{ display: 'inline-block' }}></Input>
          </Form.Item>
        </Col>
      );
    }
    if (selectOpion == 3) {
      return (
        <Col span={6}>
          <Form.Item
            name="newName"
            label={'请输入新部门名'}
            style={{ marginLeft: '20px', marginTop: '15px' }}
          >
            <Input></Input>
          </Form.Item>
        </Col>
      );
    }
    return <Col span={6}></Col>;
  };
  const handleChange = value => {
    SetselectOpion(value);
  };
  const placeHandleChange = value => {
    SetPlaceOption(value);
  };
  const StringToArray = str => {
    let arr = str.trim().split(/\s+/);
    if (arr == '') return [];
    return arr.map(val => {
      return parseInt(val);
    });
  };
  const departmentClick = () => {
    setDeButtonLoading(true);
    let deMap = new Map();
    for (let i = 0; i < departmentOriginList.length; i++) {
      deMap.set(departmentOriginList[i].departmentId, i);
    }
    let lastId;
    if (departmentOriginList.length == 0) {
      lastId = 1;
    } else lastId = departmentOriginList[departmentOriginList.length - 1].departmentId + 1;
    let deUpdate = [],
      deCreate = [],
      deDelete = [];
    let data = departmentForm.getFieldValue();
    //console.log(data);
    //console.log(departmentOriginList);
    if (data.type == undefined || data.departmentId == undefined) {
      message.warn('请选择操作和要操作的部门', 2);
      setDeButtonLoading(false);
      return;
    } else if (
      (data.type == 2 || data.type == 3) &&
      (data.newName == '' || data.newName == undefined)
    ) {
      message.warn('请输入部门名', 2);
      setDeButtonLoading(false);
      return;
    } else if (data.type == 1) {
      data.newName = '';
    }
    let departmentId = data.departmentId;
    let id = departmentId[departmentId.length - 1];
    if (data.type == 3) {
      if (id == -1) {
        message.error('不可更改根部门名', 1);
        setDeButtonLoading(false);
        return;
      }
      let tarDepart = null;
      for (let i = 0; i < departmentOriginList.length; i++) {
        if (id == departmentOriginList[i].departmentId) tarDepart = departmentOriginList[i];
      }
      if (tarDepart != null) {
        tarDepart.departmentName = data.newName;
        deUpdate.push(tarDepart);
      }
    } else if (data.type == 2) {
      if (id == -1) {
        deCreate.push({
          departmentId: lastId,
          departmentName: data.newName,
          departmentType: 1,
          departmentParent: -1,
          departmentChildren: '',
        });
      } else {
        let tarDepart = null;
        for (let i = 0; i < departmentOriginList.length; i++) {
          if (id == departmentOriginList[i].departmentId) tarDepart = departmentOriginList[i];
        }
        if (tarDepart != null) {
          deCreate.push({
            departmentId: lastId,
            departmentName: data.newName,
            departmentType: 1,
            departmentParent: tarDepart.departmentId,
            departmentChildren: '',
          });
          deUpdate.push({
            departmentId: tarDepart.departmentId,
            departmentName: tarDepart.departmentName,
            departmentType: 0,
            departmentParent: tarDepart.departmentParent,
            departmentChildren: tarDepart.departmentChildren + ' ' + lastId,
          });
        }
      }
    } else if (data.type == 1) {
      if (id == -1) {
        message.error('不可删除根部门节点', 1);
        return;
      }

      let tarDepart = null;
      for (let i = 0; i < departmentOriginList.length; i++) {
        if (id == departmentOriginList[i].departmentId) tarDepart = departmentOriginList[i];
      }
      if (tarDepart != null) {
        if (tarDepart.departmentParent != -1) {
          //先修改父节点
          let parentNode = departmentOriginList[deMap.get(tarDepart.departmentParent)];
          let t = StringToArray(parentNode.departmentChildren);
          let index = t.indexOf(tarDepart.departmentId);
          if (index > -1) {
            t.splice(index, 1);
          }
          let str = '';
          for (let i = 0; i < t.length; i++) str += t[i] + ' ';
          if (t.length == 0) parentNode.departmenType = 1;
          deUpdate.push({
            departmentId: parentNode.departmentId,
            departmentName: parentNode.departmentName,
            departmentType: parentNode.departmentType,
            departmentParent: parentNode.departmentParent,
            departmentChildren: str,
          });
        }
        //找到所有子节点Id
        let AllDelete = [];
        const dfs = id => {
          let curNode = departmentOriginList[deMap.get(id)];
          if (curNode.departmentType == 1) {
            AllDelete.push(curNode.departmentId);
            return;
          }
          let children = StringToArray(curNode.departmentChildren);
          if (children.length == 0) return;
          for (let i = 0; i < children.length; i++) dfs(children[i]);
          AllDelete.push(id);
        };
        dfs(tarDepart.departmentId);
        deDelete = AllDelete;
      }
    }
    console.log('增加', deCreate);
    console.log('修改', deUpdate);
    console.log('删除', deDelete);
    axios
      .post(Config.baseURL + '/department/change', {
        deCreate: deCreate,
        deUpdate: deUpdate,
        deDelete: deDelete,
      })
      .then(res => {
        if (res.data.code == 1) {
          message.success('更改成功', 1, () => {
            SetRefresh(!refresh);
            setDeButtonLoading(false);
            departmentForm.setFieldsValue({
              departmentId: [],
            });
          });
        } else if (res.data.code >= 10000) {
          message.error('更改失败' + res.data.message, 2);
          setDeButtonLoading(false);
        }
      })
      .catch(err => {
        message.error('更改失败，错误信息 :' + err);
        setDeButtonLoading(false);
      });
  };
  const PlaceNameRender = () => {
    if (placeOption == 2 || placeOption == 4)
      return (
        <Col span={12}>
          <Form.Item
            name="placeName"
            label={'请输入存放地名'}
            style={{ marginLeft: '20px', marginTop: '15px' }}
          >
            <Input></Input>
          </Form.Item>
        </Col>
      );
    else return <></>;
  };
  const MapClick = event => {
    if (isAvaliable) {
      if (MarkerCount == 1) {
        SetMarker1({
          show: true,
          lat: event.latlng.lat,
          lng: event.latlng.lng,
        });
      }
      if (MarkerCount == 2) {
        SetMarker2({
          show: true,
          lat: event.latlng.lat,
          lng: event.latlng.lng,
        });
      }
    }
  };
  const placeSubmit = () => {
    let lastId;
    if (placeOriginList.length == 0) {
      lastId = 1;
    } else lastId = placeOriginList[placeOriginList.length - 1].placeId + 1;
    setPlaceButtonLoading(true);
    let data = placeForm.getFieldValue();
    console.log(data);
    //检查数据
    let placeUpdate = [];
    let placeDelete = [];
    let placeCreate = [];
    if (data.type == undefined || data.placeId == undefined || data.placeId.length == 0) {
      message.error('请选择操作和存放地', 2, () => {
        setPlaceButtonLoading(false);
      });
      return;
    }
    if (data.type == 2 || data.type == 4) {
      if (data.placeName == '' || data.placeName == undefined) {
        message.error('请输入存放地名', 2, () => {
          setPlaceButtonLoading(false);
        });
        return;
      }
    }

    if (data.type == 2 || data.type == 3) {
      if (isAvaliable) {
        if (MarkerCount == 1 && Marker1.show == false) {
          message.error('请选择存放地坐标点', 2, () => {
            setPlaceButtonLoading(false);
          });
          return;
        } else if (MarkerCount == 2 && Marker2.show == false) {
          message.error('请选择存放地坐标点', 2, () => {
            setPlaceButtonLoading(false);
          });
          return;
        }
      } else {
        message.error('当前操作不可行', 2, () => {
          setPlaceButtonLoading(false);
        });
        return;
      }
    }

    let placeMap = new Map();
    for (let i = 0; i < placeOriginList.length; i++) placeMap.set(placeOriginList[i].placeId, i);
    let id = data.placeId[data.placeId.length - 1];
    if (data.type == 4) {
      if (id == -1) {
        message.error('不可修改根存放地', 2, () => {
          setPlaceButtonLoading(false);
        });
        return;
      }
      let placeDe = placeOriginList[placeMap.get(id)];
      placeUpdate.push({
        ...placeDe,
        placeName: data.placeName,
      });
    } else if (data.type == 1) {
      if (id == -1) {
        message.error('不可删除根存放节点', 2, () => {
          setPlaceButtonLoading(false);
        });
        return;
      }

      let tarPlace = null;
      for (let i = 0; i < placeOriginList.length; i++) {
        if (id == placeOriginList[i].placeId) tarPlace = placeOriginList[i];
      }
      if (tarPlace != null) {
        if (tarPlace.placeParent != -1) {
          //先修改父节点
          let parentNode = placeOriginList[placeMap.get(tarPlace.placeParent)];
          let t = StringToArray(parentNode.placeChildren);
          let index = t.indexOf(tarPlace.placeId);
          if (index > -1) {
            t.splice(index, 1);
          }
          let str = '';
          for (let i = 0; i < t.length; i++) str += t[i] + ' ';
          if (t.length == 0) parentNode.placeType = 1;
          placeUpdate.push({
            ...parentNode,
            placeChildren: str,
          });
        }
        //找到所有子节点Id
        let AllDelete = [];
        const dfs = id => {
          let curNode = placeOriginList[placeMap.get(id)];
          if (curNode.placeType == 1) {
            AllDelete.push(curNode.placeId);
            return;
          }
          let children = StringToArray(curNode.placeChildren);
          if (children.length == 0) return;
          for (let i = 0; i < children.length; i++) dfs(children[i]);
          AllDelete.push(id);
        };
        dfs(tarPlace.placeId);
        placeDelete = AllDelete;
      }
    } else if (data.type == 3) {
      let id = placeSelectList[placeSelectList.length - 1];
      let updateNode = placeOriginList[placeMap.get(id)];
      if (MarkerCount == 1)
        placeUpdate.push({
          ...updateNode,
          lat: Marker1.lat,
          lng: Marker1.lng,
        });
      else {
        placeUpdate.push({
          ...updateNode,
          lat: Marker2.lat,
          lng: Marker2.lng,
        });
      }
    } else if (data.type == 2) {
      let id = placeSelectList[placeSelectList.length - 1];
      if (id == -1) {
        placeCreate.push({
          placeId: lastId,
          placeName: data.placeName,
          placeType: 0,
          placeParent: -1,
          placeChildren: '',
          lat: Marker1.lat,
          lng: Marker1.lng,
        });
      } else {
        let tarPlace = null;
        tarPlace = placeOriginList[placeMap.get(id)];
        if (tarPlace != null) {
          placeCreate.push({
            placeId: lastId,
            placeName: data.placeName,
            placeType: 1,
            placeParent: tarPlace.placeId,
            placeChildren: '',
            lat: Marker2.lat,
            lng: Marker2.lng,
          });
          placeUpdate.push({
            ...tarPlace,
            placeType: 0,
            placeChildren: tarPlace.placeChildren + ' ' + lastId,
          });
        }
      }
    }
    console.log('create', placeCreate);
    console.log('delete', placeDelete);
    console.log('update', placeUpdate);
    axios
      .post(Config.baseURL + '/place/change', {
        placeCreate: placeCreate,
        placeDelete: placeDelete,
        placeUpdate: placeUpdate,
      })
      .then(res => {
        if (res.data.code == 1) {
          message.success('操作成功', 1, () => {
            setPlaceButtonLoading(false);
            placeForm.setFieldsValue({
              placeId: [],
            });
            SetRefresh1(!refresh1);
          });
        } else if (res.data.code >= 10000) {
          message.error('操作失败 ' + res.data.message, 2, () => {
            setPlaceButtonLoading(false);
          });
        }
      })
      .catch(err => {
        message.error('操作失败 ' + err, 2, () => {
          setPlaceButtonLoading(false);
        });
      });
  };
  const PlaceChange = value => {
    SetPlaceSelectList(value);
  };
  const BMapText = () => {
    if (placeOption == 2 || placeOption == 3 || placeOption == 4) {
      return (
        <Row gutter={[16, 35]}>
          <Col span={20}>
            <h3 style={{ textAlign: 'left' }}>
              蓝色标记表示校区/厂房，红色标记表示楼房,请点击地图定位位置:
            </h3>
          </Col>
          <Col span={4}>
            <Button type="primary">重置</Button>
          </Col>
        </Row>
      );
    } else return <></>;
  };
  return (
    <Layout className="layout">
      <Content>
        <Layout>
          <Header
            style={{
              borderRadius: '5px 5px 0px 0px',
              height: '40px',
              padding: '0px 15px',
              margin: '0px 0px',
              backgroundColor: 'white',
              textAlign: 'left',
              lineHeight: '40px',
            }}
          >
            <h3>部门配置</h3>
          </Header>
          <Content style={{ padding: '10px 0px', backgroundColor: 'white' }}>
            <div className="site-layout-content">
              <Form form={departmentForm}>
                <Row gutter={[16, 35]}>
                  <Col span={6}>
                    <div style={{ float: 'left', marginLeft: '20px' }}>
                      <Form.Item
                        name="type"
                        style={{ marginRight: '15px' }}
                        label={'选择进行的操作:'}
                      >
                        <Select
                          style={{ width: '200px' }}
                          placeholder={'选择进行的操作'}
                          onChange={handleChange}
                        >
                          <Option key={1} value={1}>
                            删除该部门及其子部门
                          </Option>
                          <Option key={2} value={2}>
                            增加子部门
                          </Option>
                          <Option key={3} value={3}>
                            更改部门名
                          </Option>
                        </Select>
                      </Form.Item>
                    </div>
                  </Col>
                  <Col span={18}></Col>
                  <Col span={18}>
                    <div style={{ float: 'left', marginLeft: '20px' }}>
                      <Form.Item
                        name="departmentId"
                        style={{ marginRight: '15px' }}
                        label={'选择要操作的部门:'}
                      >
                        <Cascader
                          style={{ width: '600px' }}
                          bordered
                          placeholder={'请选中部门'}
                          label={'请选择要更改的部门'}
                          changeOnSelect
                          options={departmentList}
                        ></Cascader>
                      </Form.Item>
                    </div>
                  </Col>
                </Row>
                <Row gutter={[16, 35]}></Row>
                <Row gutter={[16, 35]}>{SelectRender(selectOpion)}</Row>
                <Row gutter={[16, 35]}>
                  <Col span={24}>
                    <Button
                      loading={deButtonLoading}
                      onClick={departmentClick}
                      type="primary"
                      size={'large'}
                    >
                      提交
                    </Button>
                  </Col>
                </Row>
              </Form>
            </div>
          </Content>
        </Layout>
        <Layout style={{ marginTop: '30px' }}>
          <Header
            style={{
              borderRadius: '5px 5px 0px 0px',
              height: '40px',
              padding: '0px 15px',
              margin: '0px 0px',
              backgroundColor: 'white',
              textAlign: 'left',
              lineHeight: '40px',
            }}
          >
            <h3>存放地配置</h3>
          </Header>
          <Content style={{ padding: '10px 0px', backgroundColor: 'white' }}>
            <div className="site-layout-content">
              <Form form={placeForm}>
                <Row>
                  <Col span={12}>
                    <Row>
                      <Col span={24}>
                        <div style={{ float: 'left', marginLeft: '20px' }}>
                          <Form.Item
                            name="type"
                            style={{ marginRight: '15px' }}
                            label={'选择进行的操作:'}
                          >
                            <Select
                              onChange={placeHandleChange}
                              style={{ width: '200px' }}
                              placeholder={'选择进行的操作'}
                            >
                              <Option key={1} value={1}>
                                删除该存放点及其子存放地
                              </Option>
                              <Option key={2} value={2}>
                                增加子存放地
                              </Option>
                              <Option key={3} value={3}>
                                更改存放地坐标
                              </Option>
                              <Option value={4}>更改存放地名称</Option>
                            </Select>
                          </Form.Item>
                        </div>
                      </Col>
                    </Row>
                    <Row>
                      <Col span={24}>
                        <div style={{ float: 'left', marginLeft: '20px' }}>
                          <Form.Item
                            name="placeId"
                            style={{ marginRight: '15px' }}
                            label={'选择要操作的存放地:'}
                          >
                            <Cascader
                              style={{ width: '600px' }}
                              bordered
                              placeholder={'请选中存放地'}
                              label={'请选择要更改的存放地'}
                              changeOnSelect
                              onChange={PlaceChange}
                              options={placeList}
                            ></Cascader>
                          </Form.Item>
                        </div>
                      </Col>
                      {PlaceNameRender()}
                    </Row>
                  </Col>
                  <Col span={12} style={{ padding: '15px' }}>
                    {BMapText()}
                    <BMap
                      ref={mapref}
                      enableScrollWheelZoom={true}
                      center={mapCenter}
                      zoom={mapZoom}
                      enableRotate
                      enableTilt
                      heading={0}
                      tilt={mapTilt}
                      onClick={MapClick}
                      style={{ height: '500px' }}
                    >
                      {Marker1.show ? (
                        <Marker
                          icon={'simple_blue'}
                          position={{ lng: Marker1.lng, lat: Marker1.lat }}
                        />
                      ) : (
                        <></>
                      )}
                      {Marker2.show ? (
                        <Marker
                          icon={'simple_red'}
                          position={{ lng: Marker2.lng, lat: Marker2.lat }}
                        />
                      ) : (
                        <></>
                      )}
                    </BMap>
                  </Col>
                </Row>

                <Row gutter={[16, 35]}></Row>
                <Row gutter={[16, 35]}></Row>
                <Row gutter={[16, 35]}></Row>
                <Row gutter={[16, 35]}>
                  <Col span={24}>
                    <Button
                      style={{ marginTop: '40px' }}
                      loading={placeButtonLoading}
                      type="primary"
                      size={'large'}
                      onClick={placeSubmit}
                    >
                      提交
                    </Button>
                  </Col>
                </Row>
              </Form>
            </div>
          </Content>
        </Layout>
      </Content>
      <Layout style={{ marginTop: '30px' }}>
        <Header
          style={{
            borderRadius: '5px 5px 0px 0px',
            height: '40px',
            padding: '0px 15px',
            margin: '0px 0px',
            backgroundColor: 'white',
            textAlign: 'left',
            lineHeight: '40px',
          }}
        >
          <h3>审核级数</h3>
        </Header>
        <Content style={{ padding: '10px 0px', backgroundColor: 'white' }}>
          <Spin spinning={degreeLoading}>
            <Form form={degreeForm}>
              <Row>
                <Col span={2}>
                  <h3>录入级数</h3>
                </Col>
                <Col span={12}>
                  <Form.Item name="register">
                    <Radio.Group style={{ float: 'left' }} buttonStyle="solid">
                      <Radio.Button value={0}>无需审核</Radio.Button>
                      <Radio.Button value={1}>一级审核</Radio.Button>
                      <Radio.Button value={2}>二级审核</Radio.Button>
                    </Radio.Group>
                  </Form.Item>
                </Col>
              </Row>
              <Row style={{ marginTop: '20px' }}>
                <Col span={2}>
                  <h3>修改级数</h3>
                </Col>
                <Col span={12}>
                  <Form.Item name="edit">
                    <Radio.Group style={{ float: 'left' }} buttonStyle="solid">
                      <Radio.Button value={0}>无需审核</Radio.Button>
                      <Radio.Button value={1}>一级审核</Radio.Button>
                      <Radio.Button value={2}>二级审核</Radio.Button>
                    </Radio.Group>
                  </Form.Item>
                </Col>
              </Row>
              <Row style={{ marginTop: '20px' }}>
                <Col span={2}>
                  <h3>删除级数</h3>
                </Col>
                <Col span={12}>
                  <Form.Item name="delete">
                    <Radio.Group style={{ float: 'left' }} buttonStyle="solid">
                      <Radio.Button value={0}>无需审核</Radio.Button>
                      <Radio.Button value={1}>一级审核</Radio.Button>
                      <Radio.Button value={2}>二级审核</Radio.Button>
                    </Radio.Group>
                  </Form.Item>
                </Col>
              </Row>
              <Row gutter={[16, 35]}>
                <Col span={24}>
                  <Button
                    style={{ marginTop: '40px' }}
                    loading={degreeButtonLoading}
                    type="primary"
                    size={'large'}
                    onClick={degreeSubmit}
                  >
                    提交
                  </Button>
                </Col>
              </Row>
            </Form>
          </Spin>
        </Content>
      </Layout>
    </Layout>
  );
};

export default () => {
  const { authority } = UserAuth('DeConfig');
  return <>{authority ? <DeConfig></DeConfig> : <NotAuth />}</>;
};
